Handle assignment of bound methods in class bodies#19233
Handle assignment of bound methods in class bodies#19233ilevkivskyi merged 2 commits intopython:masterfrom
Conversation
This comment has been minimized.
This comment has been minimized.
JukkaL
left a comment
There was a problem hiding this comment.
Nice! The mypy primer error message change in mongo-python-driver looks odd though -- do you know what is going on there?
| == | ||
| main:3: error: Property "f" defined in "A" is read-only | ||
|
|
||
| [case testMethodMakeBoundFineGrained] |
There was a problem hiding this comment.
Add also normal incremental mode (serialization) tests case?
| x1 = A.f | ||
| x2 = A.g | ||
| x3 = A().f | ||
| x4 = A().g |
There was a problem hiding this comment.
Would it make sense to test @staticmethod as well?
There was a problem hiding this comment.
And maybe normal attribute with an explicit annotated Callable type?
There was a problem hiding this comment.
Static methods are actually unrelated to this story, they are already handled using special-casing here https://github.com/python/mypy/blob/master/mypy/checker.py#L4420-L4422. But I still added the tests, because existing tests only cover static method alias within same class. (Also attributes with explicit callable annotations are considered instance attributes, but anyway added for completeness.)
Yes, the same thing that is going on in |
|
Diff from mypy_primer, showing the effect of this PR on open source code: prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/_internal/concurrency/threads.py:37: error: Attribute function "_counter" with type "Callable[[], int]" does not accept self argument [misc]
jinja (https://github.com/pallets/jinja)
+ src/jinja2/runtime.py:370: error: Unused "type: ignore" comment [unused-ignore]
+ src/jinja2/runtime.py:384: error: Unused "type: ignore" comment [unused-ignore]
+ src/jinja2/environment.py:1290: error: Unused "type: ignore" comment [unused-ignore]
+ src/jinja2/environment.py:1311: error: Unused "type: ignore" comment [unused-ignore]
mongo-python-driver (https://github.com/mongodb/mongo-python-driver)
- pymongo/synchronous/cursor.py:1004: error: Invalid index type "int | Any | Pattern[Any]" for "list[Any]"; expected type "SupportsIndex" [index]
+ pymongo/synchronous/cursor.py:1004: error: Invalid index type "int | Any | Pattern[Any]" for "list"; expected type "SupportsIndex" [index]
- pymongo/asynchronous/cursor.py:1006: error: Invalid index type "int | Any | Pattern[Any]" for "list[Any]"; expected type "SupportsIndex" [index]
+ pymongo/asynchronous/cursor.py:1006: error: Invalid index type "int | Any | Pattern[Any]" for "list"; expected type "SupportsIndex" [index]
|
|
Thanks! |
Fixes #18438 Fixes #19146 Surprisingly, a very small change is sufficient to replicate Python runtime behavior for all the important cases (see `checkmember.py`). I also replace the `bound_args` argument of `CallableType`, that was mostly unused, with a flag (as suggested by @JukkaL) and make sure it is properly set/preserved everywhere.
Fixes #18438
Fixes #19146
Surprisingly, a very small change is sufficient to replicate Python runtime behavior for all the important cases (see
checkmember.py). I also replace thebound_argsargument ofCallableType, that was mostly unused, with a flag (as suggested by @JukkaL) and make sure it is properly set/preserved everywhere.